import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

import store from '@/store'

import layout from '@/view/layout/layout.vue'

var routes = [
    {
        path      : '/login',
        name      : 'login',
        meta      : {title : '登录', noLogin : true},
        component : () => import('@/view/login.vue')
    },

    {
        path      : '/',
        name      : 'index',
        meta      : {title : '数据监控平台'},
        component : () => import('@/view/index/index.vue')
    },
    
    {
        path      : '/agent',
        name      : 'agent',
        meta      : {title : '监控平台'},
        component : () => import('@/view/agent/index.vue')
    },

    {
        path      : '/user',
        name      : 'user',
        meta      : {title : '用户'},
        component : layout,
        children  : [
            {path : '', name : 'user', meta : {title : '用户列表'}, component : () => import('@/view/user/index.vue')}
        ]
    },

    {
        path      : '/device',
        name      : 'device',
        meta      : {title : '设备'},
        component : layout,
        children  : [
            {path : '', name : 'device', meta : {title : '设备'}, component : () => import('@/view/device/index.vue')}
        ]
    },

    {
        path      : '/order',
        name      : 'order',
        meta      : {title : '订单'},
        component : layout,
        children  : [
            {path : '', name : 'order', meta : {title : '订单'}, component : () => import('@/view/order/index.vue')}
        ]
    }
]

const router = new VueRouter({
    routes
})

router.beforeEach((to, from, next) => {
	// if(to.meta.noLogin !== true) {
	// 	if(!store.state.loginStatus || store.getters.loginExpire() <= 0){
	// 		next({path : '/login'})
	// 		return
	// 	}else {
    //         if(to.name == 'index' && store.state.userType != 0) {
    //             next({path : '/agent'})
    //             return
    //         }
    //     }
    // }

	document.title = to.meta.title

	next()
})

export default router